package cn.ben3.addondsl.model;

import org.springframework.roo.classpath.itd.InvocableMemberBodyBuilder;

import java.util.regex.Matcher;
import java.util.regex.Pattern;


public class MethodBodyBuilder {
    private String body;
    private InvocableMemberBodyBuilder bodyBuilder=new InvocableMemberBodyBuilder();
    public MethodBodyBuilder() {

    }

    public MethodBodyBuilder varLine(String line,String ...vars) {
        Pattern pattern = Pattern.compile("\\$[\\d|\\w]+\\$");

        Matcher matcher = pattern.matcher(line);
        StringBuffer sbr = new StringBuffer();
        int pos=0;
        while (matcher.find()) {
            System.out.println(true);
            matcher.appendReplacement(sbr, vars[pos]);
            pos++;
        }
        matcher.appendTail(sbr);
        bodyBuilder.appendFormalLine(sbr.toString());
        return this;
    }

    public MethodBodyBuilder line(String line) {
        bodyBuilder.appendFormalLine(line);
        return this;
    }
    public MethodBodyBuilder newLine(boolean indent) {
        bodyBuilder.newLine(indent);
        return this;
    }
    public MethodBodyBuilder newLine() {
        bodyBuilder.newLine(true);
        return this;
    }
    public MethodBodyBuilder right() {
        bodyBuilder.indent();
        return this;
    }
    public MethodBodyBuilder left() {
        bodyBuilder.indentRemove();
        return this;
    }
    public InvocableMemberBodyBuilder builder(){
        return this.bodyBuilder;
    }



}

